﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace QldtSdh.GUI.DaoTao
{
    using BLL;
    using DAL;
    using DAL.Models;
    using GUI.Utils;
    using QldtSdh.GUI.Common;
    using QldtSdh.Utils;

    public partial class FormChonLopHocPhan : QldtSdh.GUI.Common.BaseDialog
    {
        private bool _DoNotUpdateGuiBySelectedLopHocPhan = false;
        public LopHocPhan SelectedLopHocPhan
        {
            get
            {
                LopHocPhan lop = null;
                if (bsLopHocPhan.Current != null)
                    lop = bsLopHocPhan.Current as LopHocPhan;
                return lop;
            }
        }

        public FormChonLopHocPhan(List<LopHocPhan> lstLopHocPhan, string msg)
        {
            InitializeComponent();

            lblMessage.Text = msg;

            _DoNotUpdateGuiBySelectedLopHocPhan = true;
            bsLopHocPhan.DataSource = lstLopHocPhan;
            gridLopHocPhan.SetDataGridViewAsReadonly(rowHeadersVisible: true, columnHeadersVisible: true);
            gridLopHocPhan.SetDataSource(bsLopHocPhan);
            _DoNotUpdateGuiBySelectedLopHocPhan = false;
            UpdateGuiBySelectedLopHocPhan();
        }

        private void bsLopHocPhan_CurrentChanged(object sender, EventArgs e)
        {
            if (_DoNotUpdateGuiBySelectedLopHocPhan)
                return;
            UpdateGuiBySelectedLopHocPhan();
        }

        private void UpdateGuiBySelectedLopHocPhan()
        {
            var lopHocPhan = this.SelectedLopHocPhan;
            if (lopHocPhan == null)
                btnDongY.Enabled = false;
            else
                btnDongY.Enabled = true;
        }

        private void gridLopHocPhan_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0 && e.RowIndex < bsLopHocPhan.Count && bsLopHocPhan.Count > 0)
                btnDongY.PerformClick();
        }
    }
}
